public class Num008 {
    /**
     * 和大于或者等于k的最短子数组
     * @param k 极值k
     * @param nums 初始数组
     * @return 返回最短长度值
     */
    public int minSubArrayLen(int k,int[] nums){
        int left = 0;
        int sum = 0;

        int minLength = Integer.MIN_VALUE;
        for (int right = 0; right < nums.length; right++) {
            sum += nums[right];
            while (left <= right && sum >= k){
                minLength = Math.min(minLength,right-left+1);
                sum -= nums[left++];
            }
        }
        return minLength == Integer.MIN_VALUE ? 0 : minLength;
    }
}
